<template>
  <div class="bg-light">
    <div class="container-title">规则信息</div>
    <!--满减送-->
    <template v-if="type === 1 && form.activityInfoDTO">
      <Form :label-width="110">
        <Row class="pr">
          <i-col span="12">
            <FormItem label="促销类型：">
              <span>{{ form.activityInfoDTO.promotionTypeDescription }}</span>
            </FormItem>
            <FormItem label="参与方式：">
              <span>{{ form.activityInfoDTO.joinTypeEnum | filterJoinType }}</span>
            </FormItem>
            <FormItem label="优惠内容：">
              <span>{{ form.activityInfoDTO.promotionRuleDescription }} {{ form.activityFullCutGiftDTO.isParcel ? '包邮' : '' }}</span>
            </FormItem>
            <FormItem label="活动时间：">
              <div>起：{{ form.activityInfoDTO.startDate }} 止：{{ form.activityInfoDTO.endDate }}</div>
            </FormItem>
            <FormItem label="审核时间：">
              <span>{{ form.activityInfoDTO.checkDatetime }}</span>
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="活动对象：">
              <span>{{ form.activityInfoDTO.storeTypeEnumList | filterStoreType }}</span>
            </FormItem>
            <FormItem label="优惠条件：">
              <span class="font-red">{{ form.activityInfoDTO.limitStartAmount | currency(true) }}</span>
            </FormItem>
            <FormItem label="活动备注：">
              <span>{{ form.activityInfoDTO.activityDescription }}</span>
            </FormItem>
            <FormItem label="审核状态：">
              <span>{{ form.activityInfoDTO.checkStatusEnum | filterCheck }}</span>
            </FormItem>
            <FormItem label="审核描述：">
              <span>{{ form.activityInfoDTO.checkDescription }}</span>
            </FormItem>
          </i-col>
        </Row>
      </Form>
    </template>
    <!--2满赠 -->
    <template v-if="type === 2 && form.activityInfoDTO">
      <Form :label-width="110">
        <Row class="pr">
          <i-col span="12">
            <FormItem label="促销类型：">
              <span>{{ form.activityInfoDTO.promotionTypeDescription }}</span>
            </FormItem>
            <FormItem label="参与方式：">
              <span>{{ form.activityInfoDTO.joinTypeEnum | filterJoinType }}</span>
            </FormItem>
            <FormItem label="活动规则：">
              <span>{{ form.activityFullGiftDTO | combinePromotionRuleDescription(type) }}</span>
            </FormItem>
            <FormItem label="审核状态：">
              <span>{{ form.activityInfoDTO.checkStatusEnum | filterCheck }}</span>
            </FormItem>
            <FormItem label="审核描述：">
              <span>{{ form.activityInfoDTO.checkDescription }}</span>
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="活动对象：">
              <span>{{ form.activityInfoDTO.storeTypeEnumList | filterStoreType }}</span>
            </FormItem>
            <FormItem label="活动备注：">
              <span>{{ form.activityInfoDTO.activityDescription }}</span>
            </FormItem>
            <FormItem label="活动时间：">
              <div>起：{{ form.activityInfoDTO.startDate }} 止：{{ form.activityInfoDTO.endDate }}</div>
            </FormItem>
            <FormItem label="审核时间：">
              <span>{{ form.activityInfoDTO.checkDatetime }}</span>
            </FormItem>
          </i-col>
        </Row>
      </Form>
    </template>
    <!-- 4赠品促销  -->
    <template v-if="type === 4 && form.activityInfoDTO">
      <Form :label-width="110">
        <Row class="pr">
          <i-col span="12">
            <FormItem label="促销类型：">
              <span>{{ form.activityInfoDTO.promotionTypeDescription }}</span>
            </FormItem>
            <FormItem label="参与方式：">
              <span>{{ form.activityInfoDTO.joinTypeEnum | filterJoinType }}</span>
            </FormItem>
            <FormItem label="活动规则：">
              <span>{{ form.activityInfoDTO.promotionRuleDescription }}</span>
            </FormItem>
            <FormItem label="审核状态：">
              <span>{{ form.activityInfoDTO.checkStatusEnum | filterCheck }}</span>
            </FormItem>
            <FormItem label="审核描述：">
              <span>{{ form.activityInfoDTO.checkDescription }}</span>
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="活动对象：">
              <span>{{ form.activityInfoDTO.storeTypeEnumList | filterStoreType }}</span>
            </FormItem>
            <FormItem label="活动备注：">
              <span>{{ form.activityInfoDTO.activityDescription }}</span>
            </FormItem>
            <FormItem label="活动时间：">
              <div>起：{{ form.activityInfoDTO.startDate }} 止：{{ form.activityInfoDTO.endDate }}</div>
            </FormItem>
            <FormItem label="审核时间：">
              <span>{{ form.activityInfoDTO.checkDatetime }}</span>
            </FormItem>
          </i-col>
        </Row>
      </Form>
    </template>
    <!-- 5满减 -->
    <template v-if="type === 5 && form.activityInfoDTO">
      <Form :label-width="110">
        <Row class="pr">
          <i-col span="12">
            <FormItem label="促销类型：">
              <span>{{ form.activityInfoDTO.promotionTypeDescription }}</span>
            </FormItem>
            <FormItem label="参与方式：">
              <span>{{ form.activityInfoDTO.joinTypeEnum | filterJoinType }}</span>
            </FormItem>
            <FormItem label="活动规则：">
              <span>{{ form.activityFullCutDTO | combinePromotionRuleDescription(type) }}</span>
            </FormItem>
            <FormItem label="审核状态：">
              <span>{{ form.activityInfoDTO.checkStatusEnum | filterCheck }}</span>
            </FormItem>
            <FormItem label="审核描述：">
              <span>{{ form.activityInfoDTO.checkDescription }}</span>
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="活动对象：">
              <span>{{ form.activityInfoDTO.storeTypeEnumList | filterStoreType }}</span>
            </FormItem>
            <FormItem label="活动备注：">
              <span>{{ form.activityInfoDTO.activityDescription }}</span>
            </FormItem>
            <FormItem label="活动时间：">
              <div>起：{{ form.activityInfoDTO.startDate }} 止：{{ form.activityInfoDTO.endDate }}</div>
            </FormItem>
            <FormItem label="审核时间：">
              <span>{{ form.activityInfoDTO.checkDatetime }}</span>
            </FormItem>
          </i-col>
        </Row>
      </Form>
    </template>
    <!-- 6多买优惠 -->
    <template v-if="type === 6 && form.activityInfoDTO">
      <Form :label-width="110">
        <Row class="pr">
          <i-col span="12">
            <FormItem label="促销类型：">
              <span>{{ form.activityInfoDTO.promotionTypeDescription }}</span>
            </FormItem>
            <FormItem label="参与方式：">
              <span>{{ form.activityInfoDTO.joinTypeEnum | filterJoinType }}</span>
            </FormItem>
            <FormItem label="活动规则：">
              <span>{{ form.activityBuyMoreDTO | combinePromotionRuleDescription(type) }}</span>
            </FormItem>
            <FormItem label="审核状态：">
              <span>{{ form.activityInfoDTO.checkStatusEnum | filterCheck }}</span>
            </FormItem>
            <FormItem label="审核描述：">
              <span>{{ form.activityInfoDTO.checkDescription }}</span>
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="活动对象：">
              <span>{{ form.activityInfoDTO.storeTypeEnumList | filterStoreType }}</span>
            </FormItem>
            <FormItem label="活动备注：">
              <span>{{ form.activityInfoDTO.activityDescription }}</span>
            </FormItem>
            <FormItem label="活动时间：">
              <div>起：{{ form.activityInfoDTO.startDate }} 止：{{ form.activityInfoDTO.endDate }}</div>
            </FormItem>
            <FormItem label="审核时间：">
              <span>{{ form.activityInfoDTO.checkDatetime }}</span>
            </FormItem>
          </i-col>
        </Row>
      </Form>
    </template>
    <!--单品-->
    <template v-if="type === 3 && form.activityInfoDTO">
      <Form :label-width="110">
        <Row class="pr">
          <i-col span="12">
            <FormItem label="促销类型：">
              <span>{{ form.activityInfoDTO.promotionTypeDescription }}</span>
            </FormItem>
            <FormItem label="参与方式：">
              <span>{{ form.activityInfoDTO.joinTypeEnum | filterJoinType }}</span>
            </FormItem>
            <FormItem label="限购条件：">
              <span>{{ form.activitySingleDTO.limitOneOrderTypeEnum | filterLimt }}</span>
            </FormItem>
            <FormItem label="活动规则：">
              <span>{{ form.activityInfoDTO.promotionRuleDescription }}</span>
            </FormItem>
            <FormItem label="审核状态：">
              <span>{{ form.activityInfoDTO.checkStatusEnum | filterCheck }}</span>
            </FormItem>
            <FormItem label="审核描述：">
              <span>{{ form.activityInfoDTO.checkDescription }}</span>
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="活动对象：">
              <span>{{ form.activityInfoDTO.storeTypeEnumList | filterStoreType }}</span>
            </FormItem>
            <FormItem label="单品促销类型：">
              <span>{{ form.activitySingleDTO.singlePromotionTypeEnum | filterSingle }}</span>
            </FormItem>
            <FormItem label="活动备注：">
              <span>{{ form.activityInfoDTO.activityDescription }}</span>
            </FormItem>
            <FormItem label="活动时间：">
              <div>起：{{ form.activityInfoDTO.startDate }} 止：{{ form.activityInfoDTO.endDate }}</div>
            </FormItem>
            <FormItem label="审核时间：">
              <span>{{ form.activityInfoDTO.checkDatetime }}</span>
            </FormItem>
          </i-col>
        </Row>
      </Form>
    </template>
    <!--满额返券-->
    <template v-if="type === 7 && form.activityInfoDTO">
      <Form :label-width="150">
        <Row class="pr">
          <i-col span="12">
            <FormItem label="促销类型：">
              <span>{{ form.activityInfoDTO.promotionTypeDescription }}</span>
            </FormItem>
            <FormItem label="参与方式：">
              <span>{{ form.activityInfoDTO.joinTypeEnum | filterJoinType }}</span>
            </FormItem>
            <FormItem label="是否仅首次首单返券：">
              <span>{{ form.activityFullGiftCouponDTO.isFirstOrderGift ? '是' : '否' }}</span>
            </FormItem>
            <FormItem label="审核状态：">
              <span>{{ form.activityInfoDTO.checkStatusEnum | filterCheck }}</span>
            </FormItem>
            <FormItem label="审核描述：">
              <span>{{ form.activityInfoDTO.checkDescription }}</span>
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="活动对象：">
              <span>{{ form.activityInfoDTO.storeTypeEnumList | filterStoreType }}</span>
            </FormItem>
            <FormItem label="活动备注：">
              <span>{{ form.activityInfoDTO.activityDescription }}</span>
            </FormItem>
            <FormItem label="活动时间：">
              <div>起：{{ form.activityInfoDTO.startDate }} 止：{{ form.activityInfoDTO.endDate }}</div>
            </FormItem>
            <FormItem label="审核时间：">
              <span>{{ form.activityInfoDTO.checkDatetime }}</span>
            </FormItem>
            <FormItem label="优惠券：">
              <span v-if="form.activityFullGiftCouponDTO.fullGiftCouponTypeEnum == 'PRODUCT'">{{ form.activityFullGiftCouponDTO.giftCouponRuleList | giftCouponRuleList }}</span>
              <span v-else>
                <span v-for="(item,index) in form.couponList" :key="index">
                  返劵金额{{ item.custom }}元 , 使用条件{{ item.useCondition }}元 , 有效期{{ item.validityDays }}天
                </span>
              </span>
            </FormItem>
          </i-col>
        </Row>
        <Row v-if="form.activityFullGiftCouponDTO.fullGiftCouponTypeEnum !== 'PRODUCT'">
          <i-col span="24">
            <FormItem label="活动规则：">
              <span>用户在{{ form.activityFullGiftCouponDTO.limitCompleteDatetime }}前完成订单，并且在{{ form.activityFullGiftCouponDTO.limitReturnDate }}天内未申请退款，{{ form.couponList | combinePromotionRuleDescription(type) }}</span>
            </FormItem>
          </i-col>
        </Row>
      </Form>
    </template>
    <!--工厂促销-->
    <template v-if="type === 8 && form.activityInfoDTO">
      <Form :label-width="170">
        <Row class="pr">
          <i-col span="12">
            <FormItem label="促销类型：">
              <span>{{ form.activityInfoDTO.promotionTypeDescription }}</span>
            </FormItem>
            <FormItem label="活动标签：">
              <span>{{ form.activityInfoDTO.promotionTagName }}</span>
            </FormItem>
            <FormItem label="参与方式：">
              <span>{{ form.activityInfoDTO.joinTypeEnum | filterJoinType }}</span>
            </FormItem>
            <FormItem label="宣传语：">
              <div class="e1">{{ form.activityFactoryInfoDTO.advertisingSlogan }}</div>
            </FormItem>
            <FormItem label="审核状态：">
              <span>{{ form.activityInfoDTO.checkStatusEnum | filterCheck }}</span>
            </FormItem>
            <FormItem label="审核描述：">
              <span>{{ form.activityInfoDTO.checkDescription }}</span>
            </FormItem>
            <FormItem v-if="form.activityFactoryInfoDTO.phoneList && form.activityFactoryInfoDTO.phoneList.length" label="手机号：">
              <span>{{ form.activityFactoryInfoDTO.phoneList.join(',') }}</span>
            </FormItem>
            <FormItem label="例外限购对象：">
              {{ form.activityFactoryInfoDTO.exceptionalTypeEnum | exceptionalTypeText }}
            </FormItem>
            <FormItem v-if="form.activityFactoryInfoDTO.exceptionalTypeEnum == 'STORE'" label="例外门店限购数量">
              {{ form.activityFactoryInfoDTO.exceptionalCount }}<span class="link" @click="onShowStoreList(0)">（查看）</span>
            </FormItem>
            <FormItem v-if="form.activityFactoryInfoDTO.exceptionalTypeEnum == 'DISTRIBUTOR'" label="例外经销商限购数量">
              {{ form.activityFactoryInfoDTO.exceptionalCount }}<span class="link" @click="onShowStoreList(1)">（查看）</span>
            </FormItem>
            <FormItem v-if="form.activityFactoryInfoDTO.exceptionalTypeEnum == 'PRODUCT'" label="例外规格限购数量">
              {{ form.activityFactoryInfoDTO.exceptionalCount }}<span class="link" @click="onShowStoreList(2)">（查看）</span>
            </FormItem>
            <FormItem label="包邮：">
              {{ form.activityFactoryInfoDTO | combinePromotionRuleDescription(type) }}
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="限购数量类型：">
              <span>{{ form.activityFactoryInfoDTO.limitTypeEnum == 1 ? '按门店类型限购': '通用门店限购' }}</span>
            </FormItem>
            <FormItem label="积分返利/优惠券激活限时：">
              <span>起：{{ form.activityFactoryInfoDTO.activeLimitStartTime }} 止：{{ form.activityFactoryInfoDTO.activeLimitEndTime }}</span>
            </FormItem>
            <FormItem label="活动时间：">
              <div>起：{{ form.activityInfoDTO.startDate }} 止：{{ form.activityInfoDTO.endDate }}</div>
            </FormItem>
            <FormItem label="审核时间：">
              <span>{{ form.activityInfoDTO.checkDatetime }}</span>
            </FormItem>
            <FormItem v-if="form.activityFactoryInfoDTO.warningQuantity" label="阈值：">
              <span>{{ form.activityFactoryInfoDTO.warningQuantity }}</span>
            </FormItem>
            <FormItem label="参与经销商：">
              <div style="position: relative;">
                <span class="e2" style="width: 90%; ">{{(form.activityFactoryInfoDTO && form.activityFactoryInfoDTO.distributorJoinTypeEnum == 'PART') ? disributorData : '全部经销商'}}<label @click="modal2 = true" class="tips">详情</label></span>
              </div>
            </FormItem>
            <FormItem label="开启锁屏消息：">
              <span>{{ form.activityFactoryInfoDTO.isOpenMsg ? '是' : '否' }}</span>
            </FormItem>
            <FormItem label="锁屏信息：" v-if="form.activityFactoryInfoDTO.isOpenMsg">
              <div style="position: relative;">
                <span class="e2" style="width: 90%; ">{{bargainRemindList}}<label @click="modal1 = true" class="tips">详情</label></span>
              </div>
            </FormItem>
          </i-col>
        </Row>
        <Row>
          <i-col span="12">
            <FormItem label="限购数量：">
              <span v-if="form.activityFactoryInfoDTO.limitTypeEnum !== 'STORE_TYPE'">通用门店限购数量<span class="font-red">{{ form.activityFactoryInfoDTO.commonLimitNumber }}</span></span>
              <span v-else>{{ filterstore }}</span>
            </FormItem>
          </i-col>
          <i-col>
            <FormItem label="水印图片：">
              <img :src="preFixPath + form.activityFactoryInfoDTO.mainImg + '_100w'" alt="">
            </FormItem>
          </i-col>
        </Row>
      </Form>
    </template>
    <storeList ref="storeList"></storeList> 
    <Modal
        v-model="modal1"
        title="锁屏信息"
        ok-text="关闭"
        cancel-text="">
        <p>{{bargainRemindList}}</p>
    </Modal>
    <Modal
        v-model="modal2"
        title="参与经销商"
        ok-text="关闭"
        cancel-text="">
        <p>{{(form.activityFactoryInfoDTO && form.activityFactoryInfoDTO.distributorJoinTypeEnum == 'PART') ? disributorData : '全部经销商'}}</p>
    </Modal>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import storeList from './StoreListItem'
import { preFixPath } from '@/util'
export default {
  components: {
    storeList
  },
  props: {
    type: {
      type: Number
    },
    form: {
      type: Object
    }
  },
  data () {
    return {
      couponList: [],
      modal1: false,
      modal2: false
    }
  },
  created () {
    window.couponList = this.$store.state.fullReturnSale.FullreturnForm.giftCoupon
    this.$store.dispatch('getStoreType').then(res => {
      window.storeTypeData = this.storeTypeData
    })
    window.storeTypeData = this.storeTypeData
  },
  methods: {
    onShowStoreList (type) {
      this.$refs.storeList.setShowMotal(type)
    }
  },
  computed: {
    ...mapGetters([
      'filterstoreType',
      'storeTypeData'
    ]),
    filterstore (value) {
      let text = JSON.parse(JSON.stringify(this.filterstoreType))
      text.forEach(item => {
        item.num = ''
        item.totalNum = ''
      })
      text.forEach(todo => {
        this.form.activityFactoryInfoDTO.storeTypeLimitNumberDTOList && this.form.activityFactoryInfoDTO.storeTypeLimitNumberDTOList.forEach((item, index) => {
          if (item && (item.storeTypeEnum == todo.value)) {
            todo.num = item.limitNumber
            todo.totalNum = item.totalLimitNumber ? item.totalLimitNumber : ''
          }
        })
      })
      let tt = text.map(item => {
        if (item.num) {
          return item.name + `(规格限购：${item.num},` + `总量限购：${item.totalNum})`
        } else if (!item.isChecked) {
          return item.name + '(不参与活动)'
        } else {
          return item.name + '(不限制)'
        }
      })
      return tt.join('、')
    },
    disributorData (value) {
      let text = ''
      if (this.form.distributorList && !this.form.distributorList.length) {
        text = '全部经销商'
      } else {
        this.form.distributorList && this.form.distributorList.forEach((item, index, array) => {
          if (index + 1 == array.length) {
            text = text + item.name
          } else {
            text = text + item.name + '、'
          }
        })
      }
      return text
    },
    bargainRemindList (state, getters) {
      let word = ''
      if (this.form.activityFactoryInfoDTO && this.form.activityFactoryInfoDTO.factoryMsgDTOList) {
        this.form.activityFactoryInfoDTO.factoryMsgDTOList.forEach((item, index) => {
          let text = ''
          if (item.msgStatusEnum == 'ON' || item.msgStatusEnum == 'OVER') {
            if (index == 0) {
              text = `活动开始前${item.msgHours}小时：`
            } else if (index == 1) {
              text = `活动开始时：`
            } else if (index == 2) {
              text = `活动结束前${item.msgHours}小时：`
            }
            word = word + text + item.msgContent + '。'
          }
        })
      }
      return word
    },
    preFixPath (state, getters) {
      if (this.form.activityFactoryInfoDTO.mainImg.indexOf('http') !== -1) {
        return ''
      } else {
        return preFixPath
      }
    }
  },
  filters: {
    filterStoreType (value) {
      let list = window.storeTypeData
      let text = []
      value.forEach(item => {
        return list.forEach(todo => {
          if (item == todo.value) {
            text.push(todo.text)
          }
        })
      })
      return text.join(',')
    },
    giftCouponRuleList (val) {
      return val.map(item => `单个订单满${item.m}个商品返${window.couponList[item.n]}${item.isParcel ? ' 包邮' : ''}`).join('，')
    },
    filterJoinType (value) {
      let list = {
        'WHOLE': '全场参与',
        'PART': '部分参与',
        'PART_NOT': '部分不参与'
      }
      return list[value]
    },
    filterLimt (value) {
      let list = {
        'ALL_NOT': '全部不限制',
        'ALL': '全部限制',
        'ACCOUNT': '限制账号',
        'IP_UUID': '限制IP/UUID'
      }
      return list[value]
    },
    filterSingle (value) {
      let list = {
        'PRICE_REDUCTION': '直降',
        'TIME_LIMIT': '限时抢购'
      }
      return list[value]
    },
    filterCheck (value) {
      let list = {
        'UNCHECKED': '未审核',
        'PASS': '审核通过',
        'REJECT': '驳回'
      }
      return list[value]
    },
    exceptionalTypeText (value) {
      let list = {
        'STORE': '门店',
        'PRODUCT': '商品',
        'DISTRIBUTOR': '经销商'
      }
      return list[value]
    },
    combinePromotionRuleDescription (value, type) {
      let text = '测试'
      let tempMap
      switch (type) {
        case 2:
          // 2满赠
          tempMap = {
            //加价购促销
            ADD_PRICE: item => `满${item.m}元可换购1件${item.isParcel ? ' 包邮' : ''}`,
            // 满赠促销
            FULL_GIFT: item => `满${item.m}元送赠品${item.isParcel ? ' 包邮' : ''}`
          }
          text = value.fullGiftRuleList.map(item => tempMap[value.fullGiftTypeEnum](item)).join('，')
          break
        case 5:
          // 5满减
          tempMap = {
            PER_FULL_CUT: item => `每满${item.m}元减${item.n}元${item.isParcel ? ' 包邮' : ''}`,
            STEP_FULL_CUT: item => `满${item.m}元减${item.n}元${item.isParcel ? ' 包邮' : ''}`
          }
          text = value.fullCutRuleList.map(item => tempMap[value.fullCutTypeEnum](item)).join('，')
          break
        case 6:
          // 6多买优惠
          tempMap = {
            M_MINUS_N: item => `满${item.m}件减最低价${item.n}件${item.isParcel ? ' 包邮' : ''}`,
            M_DISCOUNT_N: item => `满${item.m}件${item.n}折${item.isParcel ? ' 包邮' : ''}`,
            M_SELECT_N: item => `最贵${item.n}件${item.m}元${item.isParcel ? ' 包邮' : ''}`
          }
          text = value.buyMoreRuleList.map(item => tempMap[value.buyMoreTypeEnum](item)).join('，')
          break
        case 7:
          // --满额返券--
          text = value.map(item => `满${item.value}元返${item.useCondition}减${item.custom}元券${item.isParcel ? ' 包邮' : ''}`).join('，')
          break
        case 8:
          // 工厂特价
          text = value.isParcel
            ? value.parcelContent.factoryParcelTypeEnum === 'PRODUCT_NUM' ? `订单商品总数量满${value.parcelContent.num}件包邮` : `订单总金额满${value.parcelContent.amount}包邮`
            : '-'
          break
        default:
          break
      }
      return text
    }
  },
  watch: {
    form (val) {
      this.form = val
    }
  }
}
</script>


<style lang="less" scoped>
.tips {
  position: absolute;
  right: 0; bottom: 0;
  cursor: pointer;
  color: blue;
}
</style>
